package com.sunshine.util;

import com.sunshine.constant.StatusCode;

import java.util.HashMap;
import java.util.Map;

/**
 * 生成返回数据
 *
 * @author Wenjun Wu
 * @version 2.0
 * @since 2.0
 */
public class Result {

    public static Map<String, Object> json(int status, Object result) {
        return json(status, "data", result);
    }

    public static Map<String, Object> json(int status) {
        return json(status, null);
    }

    public static Map<String, Object> json(int status, String resultField, Object result) {
        Map<String, Object> map = new HashMap<>();
        map.put("status", status);
        if (result == null) {
            return map;
        }

        map.put(resultField, result);
        return map;
    }

    public static Map<String, Object> result(Object result) {
        return json(StatusCode.SUCCESS, result);
    }
}
